92 add automated tests for critical functionality #120
+1,465
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Core functionality (compatibility checks, build persistence, GraphQL resolvers and build publishing) had little or no automated test coverage, which made regressions hard to catch. This PR adds tests for the most important parts, prioritising compatibility checks and backend validation.
Changes
checkCompatability.test.ts: compatible and incompatible combinations for CPU/motherboard, RAM, case, GPU, PSU, cooler and storage, plus missing, negative and non-numeric data staying "unknown", an empty build, and several parts in one category.BuildProvider.test.tsx: loading saved builds, handling of invalid or corruptedlocalStoragedata (broken JSON, empty values,null, non-object JSON, the browser refusing to read or save), and adding, replacing, removing and clearing parts.BuildProvideraccepted valid JSON that was not an object (for example a string or array) as the saved build. It now only accepts a plain object.publishBuild.test.ts: valid publishing (trimming, length limits, parts stored in the right columns, user input kept out of the SQL) and ten kinds of invalid requests, each verified to save nothing.catalogResolvers.test.ts: thepartsresolver (pagination cursors, page-size limits, filters, sorting, attribute filters),part,manufacturers,builds, and thePart/Buildfield resolvers.config.js(the config loadsdotenvand needsDATABASE_URL, which tests do not have).npm testinbackend/server) in the README.Related issues
Closes #92
Verification
Automated checks:
backend/server:npm testpasses all 76 tests (46 new in this PR).frontend:npm testpasses all 81 tests (50 new).Screenshots
Not applicable
Checklist